/**
 * Project Name:SL_Store
 * File Name:D_BizDaoImpl.java
 * Package Name:dao.impl.d_bank
 * Date:2018年5月7日上午10:16:18
 * Copyright (c) 2018, bluemobi All Rights Reserved.
 */

package dao.impl.d_bank;

import java.util.ArrayList;
import java.util.List;

import dao.BaseDao;
import dao.BizDao.d_bank.D_BizDao;
import entity.d_bank.Page;
import entity.d_bank.d_basicuser;

/**
 * Description: <br/>
 * Date: 2018年5月7日 上午10:16:18 <br/>
 * 
 * @author songhang
 * @version
 * @see
 */
public class D_BizDaoImpl extends BaseDao implements D_BizDao {

    public List<d_basicuser> getBasicUser() {
        List<d_basicuser> listd = new ArrayList<d_basicuser>();
        try {
            String sql = "SELECT * FROM d_basicuser";
            pst = getCon().prepareStatement(sql);
            rs = pst.executeQuery();
            while (rs.next()) {
                d_basicuser dba = new d_basicuser();
                dba.setDdate(rs.getDate(1));
                dba.setDtime(rs.getString(2));
                dba.setDdesc(rs.getString(3));
                dba.setDyumoney(rs.getFloat(4));
                dba.setDchumoney(rs.getFloat(5));
                dba.setDsmoney(rs.getFloat(6));
                listd.add(dba);// 装箱
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            close(cs, con, pst, rs);
        }

        return listd;
    }

    public int getsum() {
        int oo = 0;
        Page page = new Page();
        try {
            String sql = "SELECT COUNT(1)FROM d_basicuser";
            pst = getCon().prepareStatement(sql);
            rs = pst.executeQuery();
            while (rs.next()) {
                page.setSumsize(rs.getInt(1));// 设置总条数
                int i = page.getSumsize();// 获取总条数的值8
                oo = ((i % 4 == 0) ? i / 4 : i / 4 + 1);
                page.setLastpage(oo);// 设置尾页的数
                oo = page.getLastpage();// 获取尾页的数是2
            }

        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        } finally {
            close(cs, con, pst, rs);
        }

        return oo;// 返回尾页的数
    }

    public List<d_basicuser> getNewsInfoPageById(Page page) {
        List<d_basicuser> listpro = new ArrayList<d_basicuser>();
        try {
            String sql = "SELECT * FROM d_basicuser LIMIT ?,?";
            pst = getCon().prepareStatement(sql);
            pst.setInt(1, (page.getCurrentpage() - 1) * page.getPagesize());
            pst.setInt(2, page.getPagesize());
            rs = pst.executeQuery();
            while (rs.next()) {
                d_basicuser dba = new d_basicuser();
                dba.setDdate(rs.getDate(1));
                dba.setDtime(rs.getString(2));
                dba.setDdesc(rs.getString(3));
                dba.setDyumoney(rs.getFloat(4));
                dba.setDchumoney(rs.getFloat(5));
                dba.setDsmoney(rs.getFloat(6));
                listpro.add(dba);// 装箱
            }
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        } finally {
            close(cs, con, pst, rs);
        }

        return listpro;

    }

}
